<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/25 0025
 * Time: 上午 9:56
 */

namespace App\Api\Service\Plate\Controllers;

use App\Eloquent\Ygt\BuyersProduct;
use App\Eloquent\Ygt\Customer;
use App\Engine\Buyers;
use Framework\BaseClass\Api\Controller;
use App\Eloquent\Ygt\Plate;
use App\Eloquent\Ygt\PlateSearch;
use App\Eloquent\Ygt\Branch;
use App\Engine\Func;
use App\Eloquent\Ygt\DepartmentUser;
use Illuminate\Support\Facades\Log;
use League\Fractal\Resource\Collection;

class IndexController extends Controller
{
    /**
     * @return array
     * 获取版列表
     */
    public function getList()
    {
        $userId = Func::getHeaderValueByName('userid');
        $userInfo = DepartmentUser::getCurrentInfo($userId);
        $companyId = isset($userInfo['company_id']) ? $userInfo['company_id'] : '';



        //如果是客商,企业ID需要调整
        if($companyId == 2){
            $customerId = request('customer_id');
            if($customerId){
                $customerObj = \App\Eloquent\Ygt\Customer::where(['id'=>$customerId])->first();
                if($customerObj){
                    $companyId = $customerObj->company_id;
                }
            }
        }


        $requestCompanyId   = request('company_id',0);
        $companyId  = $requestCompanyId == 0 ? $companyId : $requestCompanyId;
        $plateModel = new Plate();

        $where = [
            'company_id' => $companyId
        ];



        //数量预警
        if ($numberWarningCase = request('is_number_warning')) {
            switch ($numberWarningCase) {
                case 'yes':
                    $where['warning_number'] = ['!=', 0];
                    $where[] = ['whereRaw', 'finish_number >= warning_number'];
                    break;
                case 'no':
                    $where[] = ['whereRaw', 'finish_number < warning_number'];
                    break;
            }
        }
        //订单次数预警
        //印刷时间预警

        $fields = '*';

        $page = request('page');
        $limit = 10;
        $offset = ($page - 1) * $limit;

        $plateModel = $plateModel->where([
                ['company_id','=', $companyId ]
            ]);

        if ($categoryId = request('category_id')) {
            $where['category_id'] = $categoryId;
            $plateModel = $plateModel->where('category_id',$categoryId);
        }
        if ($customerId = request('customer_id')) {
            $where['customer_id'] = $customerId;
            $plateModel = $plateModel->where('customer_id',$customerId);
        }

        //筛选品名
        if($plateNameId = request('plate_name_id')){
            $plateModel = $plateModel->where('plate_name',$plateNameId);
        }

        //如果是销售员且不是下单人，版列表只展示对应客户的版
        $privilegeIdList = \App\Engine\OrderEngine::getPrivilegeByNode($companyId, 13);//销售员
        if (in_array($userInfo['privilege_id'], $privilegeIdList)) {
            $privilegeIdList2 = \App\Engine\OrderEngine::getPrivilegeByNode($companyId, 1);//下单人权限
            if (!in_array($userInfo['privilege_id'], $privilegeIdList2)) {
                $customerIdArr = \App\Eloquent\Ygt\Customer::where(['add_user_id'=>$userId])->get()->pluck('id');
                $plateModel = $plateModel->whereIn('customer_id',$customerIdArr);
                }
        }


        //客商进入版列表页面时
        if($userInfo['company_id'] == 2){
            $customerId = request('customer_id');
            if(!$customerId){
                //userId对应的客户ID
                $customerObj = \App\Eloquent\Ygt\Customer::where(['user_id'=>$userId]);
                $postCompanyId = request('company_id');
                $where = [];
                if($postCompanyId){
                    $customerObj = $customerObj->where(['company_id'=>$postCompanyId]);
                }

                $customerObj = $customerObj->first();
                if($customerObj){
                    $where['customer_id'] = $customerObj->id;
                    $plateModel = $plateModel->where('customer_id',$customerObj->id);
                }

            }
        }


        if ($buyerId = request('buyer_id')) {
            $where['buyer_id'] = $buyerId;
            $plateModel = $plateModel->where('buyer_id',$buyerId);
        }

        if ($plateName = request('plate_name')) {
            $where['plate_name'] = ['like', '%' . $plateName . '%'];
            $plateModel = $plateModel->where('plate_name','like','%' . $plateName . '%');
        }


        if($keyword = request('keyword')){
            $plateModel = $plateModel->where(
                function ($query) use($keyword,$companyId) {
                    $customerIds = Customer::where([['company_id','=', $companyId ],['customer_name','like', '%' . $keyword . '%']])->get()->pluck('id');
                    $buyeyIds = \App\Eloquent\Ygt\Buyers::where([['company_id','=', $companyId ],['buyer_name','like', '%' . $keyword . '%']])->get()->pluck('id');

                    $productBuyerIds = BuyersProduct::where('name','like','%' . $keyword . '%')->get()->pluck('id');

                    $query
                        //->orWhere([['plate_name','like', '%' . $keyword . '%']])
                        ->orWhereIn('plate_name',$productBuyerIds)
                        ->orWhere([
                            ['plate_no','like', '%' . $keyword . '%']
                        ])->orWhereIn('customer_id', $customerIds)->orWhereIn('buyer_id', $buyeyIds);
                }
            );

            $plateSearchModel = new PlateSearch();
            $plateSearchInfo = PlateSearch::where('uid',$userId)->first();
            if($plateSearchInfo){
                $content = unserialize($plateSearchInfo['content']);
                array_unshift($content,$keyword);
                $content = array_slice(array_unique($content),0,10);
                PlateSearch::updateOneData(['uid'=>$userId],['content'=>serialize($content)]);
            }else{
                $content[] = $keyword;
                PlateSearch::insertOneData(['uid'=>$userId,'content'=>serialize($content)]);
            }
        }

        $count = $plateModel->count();

        if($customerId){
            $fields = ['*',\DB::raw(sprintf('abs(customer_id-%d) as c_i_ind',$customerId))];
            $plateModel = $plateModel->select($fields)
                ->skip($offset)
                ->orderBy('c_i_ind','asc')
                ->take($limit)->orderBy('last_time', 'desc');
        }
        else{
            $plateModel = $plateModel->select($fields)
                ->skip($offset)
                ->take($limit)->orderBy('last_time', 'desc');
        }
//            ->orderBy('ygt_product.id','desc')

        $result = $plateModel->get();

//        $result = $plateModel->getData($where, $fields, $limit, $offset);

        $list = $result->map(function ($item, $key) {
            $tmp = $this->composeInfo($item);
            /*$categoryInfo = Plate::getCategory($item->category_id);
            $tmp = [
                'id' => $item->id,
                'plate_name' => $item->plate_name,
                'plate_no' => $item->plate_no,
                'position' => $item->position,
                'finish_number' => $item->finish_number,
                'warning_number' => $item->warning_number,
                'order_times' => $item->order_times,
                'warning_order_times' => $item->warning_order_times,
                'last_time' => $item->last_time,
                'warning_days' => $item->warning_days,
                'spec' => $item->spec,
                'factory' => $item->factory,
                'factory_plate_no' => $item->factory_plate_no,
                'customer_id' => $item->customer_id,
                'customer_name' => $item->customer->customer_name,
//                'category_id' =>$item->category_id,
                'branch' => $item->branch,
                'branch_number' => count($item->branch),
                'category_name' => isset($categoryInfo['title']) ? $categoryInfo['title'] : '',
                'img_url' => Func::getImgUrlById($item['img_id']),
                'img_id' => $item['img_id'],
                'is_warning' => $item['is_warning'],
                'remark' => $item['remark']
            ];
            $tmp['warning_info'] = [];
            //条数预警
            if($item->warning_number > 0 and $item->finish_number > $item->warning_number){
                $tmp['warning_info'][] = '已印刷：'.$item->finish_number.'条,超出预警'.($item->finish_number-$item->warning_number).'条';
            }
            if($item->warning_order_times > 0 and $item->order_times > $item->warning_order_times){
                $tmp['warning_info'][] = '已印刷订单'.$item->order_times.'，超出预警'.($item->order_times-$item->warning_order_times).'次';
            }
            if($item->warning_days > 0 and $item->warning_time < time()){
                $overDays = floor((time()-$item->warning_time)/86400);
                $tmp['warning_info'][] = ($item->warning_days+$overDays).'天未生产,超出预警'.$overDays.'天';
            }*/
            return $tmp;
        })->toArray();

//        $count = $plateModel->getCount($where);

        $pagingData = [
            'page' => $page,
            'pageSize' => $limit,
            'total' => $count,
            'keyword' => ''
        ];
        return $this->pagingData($list, $pagingData);

    }

    public function getInfo(){
        $where = [
            'id'=>request('id')
        ];
        $rules = [
            'id' => 'required|integer',
        ];
        $this->validateRequestParameters($where, $rules);

        $plateModel = new Plate();
        if($item = $plateModel->getOneData($where)){
            $info = $this->composeInfo($item);

            //追加版支详情
            $branch = [
                'fixed_plate' => [],
                'colourplate' => [],
            ];
            $plateBranchList = \App\Eloquent\Ygt\PlateBranch::where(['plate_id'=>request('id')])->get();
            foreach ($plateBranchList as $plateBranchRow){
                if($plateBranchRow['type'] == 1){
                    $branch['fixed_plate'][] = [
                        'id' => $plateBranchRow['id'],
                        'name' => $plateBranchRow['name'],
                        'is_choose' => $plateBranchRow['is_choose'],//1-选中，0-未选中]
                        'is_delete' => $plateBranchRow['is_delete'],//是否可删除 1-可删除 0-不可删除
                    ];
                }

                if($plateBranchRow['type'] == 2){
                    $tmpPlateBranchId = $plateBranchRow['id'];

                    $tmpModelList=[];
                    $tmpPlateBranchColourplateList = \App\Eloquent\Ygt\PlateBranchColourplate::where(['plate_branch_id'=>$tmpPlateBranchId])->get();
                    foreach ($tmpPlateBranchColourplateList as $tmpPlateBranchColourRow){
                        $tmpModelList[] = $tmpPlateBranchColourRow['name'];
                    }

                    $branch['colourplate'][] = [
                        'id' => $plateBranchRow['id'],
                        'name' => $plateBranchRow['name'],
                        'is_choose' => $plateBranchRow['is_choose'],//1-选中，0-未选中
                        'is_delete' => $plateBranchRow['is_delete'],//是否可删除 1-可删除 0-不可删除
                        'model' => $tmpModelList,
                    ];
                }


                if($plateBranchRow['type'] == 3){
                    $branch['other_plate'][] = [
                        'id' => $plateBranchRow['id'],
                        'name' => $plateBranchRow['name'],
                        'is_delete' => $plateBranchRow['is_delete'],//是否可删除 1-可删除 0-不可删除
                    ];
                }

            }

            $info['branch'] = $branch;
            return $info;
        }else{
            return [
                'code' => 1,
                'message' => '版信息不存在',
            ];
        }
    }


    private function composeInfo($item){
        $categoryInfo = Plate::getCategory($item->category_id);

        //板规格显示处理
        $specName = '';
        if($item->spec){
            $tmpSpecArr = explode(',',$item->spec);
            if(count($tmpSpecArr) == 2){
                if($tmpSpecArr[0] || $tmpSpecArr[1]){
                    $specName = $tmpSpecArr[0].'×'.$tmpSpecArr[1].'厘米';
                }
            }
        }

        //版品名处理
        $buyersProdcutObj = \App\Eloquent\Ygt\BuyersProduct::where(['id'=>$item->plate_name])->first();
        if($buyersProdcutObj){
            $plateShowName = $buyersProdcutObj->name;
        }else{
            $plateShowName = $item->plate_name;
        }



        $tmp = [
            'id' => $item->id,
            'plate_name' => $item->plate_name,
            'plate_show_name' => $plateShowName,
            'plate_no' => $item->plate_no,
            'position' => $item->position,
            'finish_number' => $item->finish_number.'条',
            'warning_number' => $item->warning_number,
            'order_times' => $item->order_times,
            'warning_order_times' => $item->warning_order_times,
            'last_time' => $item->last_time,
            'warning_days' => $item->warning_days,
            'spec' => $item->spec,
            'spec_name' => $specName,
            'factory' => $item->factory,
            'factory_plate_no' => $item->factory_plate_no,
            'customer_id' => $item->customer_id,
            'customer_name' => isset($item->customer->customer_name)?$item->customer->customer_name:'',
            'buyer_id' => $item->buyer_id,
            'buyer_name' => isset($item->buyer->buyer_name)?$item->buyer->buyer_name:'',
            'category_id' =>$item->category_id,
            'branch' => $item->branch,
            'branch_number' => $item->branch_number,
//            'branch_number' => count($item->branch),
            'category_name' => isset($categoryInfo['title']) ? $categoryInfo['title'] : '',
            'img_url' => Func::getImgUrlById($item['img_id']),
            'img_id' => $item['img_id'],
            'is_warning' => $item['is_warning'],
            'remark' => $item['remark'],
            'print_date' => $item['print_date'] ? $item['print_date'] : '',
            'print_direction' => $item['print_direction'] ? $item['print_direction'] : '',
            'pattern_specification' => $item['pattern_specification'] ? $item['pattern_specification'] : '',
            'membrane_specification' => $item['membrane_specification'] ? $item['membrane_specification'] : '',
            'surface_printing' => $item['surface_printing'] ? $item['surface_printing'] : '',
            'M_width' => $item['M_width'] ? $item['M_width'] : '',
            'pattern_radion' => $item['pattern_radion'] ? $item['pattern_radion'] : '',
            'chip_specification_length' => $item['chip_specification_length'] ? $item['chip_specification_length'] : '',
            'finished_specification' => $item['finished_specification'] ? $item['finished_specification'] : '',
            'chip_specification_length_name' => \App\Engine\OrderEngine::getOrderFiledValueTrue($item->chip_specification_length,15),
            'finished_specification_name' => \App\Engine\OrderEngine::getOrderFiledValueTrue($item->finished_specification,16),
        ];
        $buyerName                 = Buyers::getNameById($item->buyer_id);
        $tmp['buyer_name']        = $buyerName ? $buyerName : '';
        $orderTypeTitle             = '';
        $tmp['order_type_title'] = $orderTypeTitle;
        $tmp['warning_info'] = [];
        //条数预警
        if($item['is_warning'] == 'yes'){
            if($item->warning_number > 0 and $item->finish_number > $item->warning_number){
                $tmp['warning_info'][] = '已印刷：'.$item->finish_number.'条,超出预警'.($item->finish_number-$item->warning_number).'条';
            }
            if($item->warning_order_times > 0 and $item->order_times > $item->warning_order_times){
                $tmp['warning_info'][] = '已印刷订单'.$item->order_times.'，超出预警'.($item->order_times-$item->warning_order_times).'次';
            }
            $itemArr    = $item->toArray();
            $warningDays= $itemArr['warning_days'];
            $itemLastTime   = intval($itemArr['last_time']);
            $lastTime   = $itemLastTime ? $itemLastTime : $itemArr['created_at'];
            $nowTime    = $_SERVER['REQUEST_TIME'];
            $days       = ceil(($nowTime - $lastTime)/86400);
            if($item->warning_days>0 && $days>$warningDays ){
                $overDays = $days - $warningDays;
                $tmp['warning_info'][] = ($item->warning_days+$overDays).'天未生产,超出预警'.$overDays.'天';
            }
        }

        //新增处理字段
        $tmp['M_width_name'] = '';//M边宽度
        if($tmp['M_width']){
            $tmp['M_width_name'] = $tmp['M_width'].'厘米';
        }

        $tmp['membrane_specification_name'] = '';//膜规格
        if($tmp['membrane_specification']){
            $tmp['membrane_specification_name'] = $tmp['membrane_specification'].'厘米';
        }

        $tmp['pattern_specification_name'] = '';//图案规格
        if($tmp['pattern_specification']){
            $tmpArr = explode(',',$tmp['pattern_specification']);
            if(count($tmpArr) == 2){
                if($tmpArr[0] || $tmpArr[1]){
                    $tmp['pattern_specification_name'] = $tmpArr[0].'×'.$tmpArr[1].'厘米';
                }
            }
        }

        return $tmp;
    }

    /**
     * @return array
     * 获取版分类
     */
    public function getCategoryList()
    {
        $plateCategoryList = Plate::getCategory();
        return array_values($plateCategoryList);
    }

    /**
     * @return array
     * 添加版
     */
    public function plateAdd()
    {

        $params = request()->only('customer_id', 'buyer_id', 'category_id', 'plate_name', 'img_id', 'plate_no', 'position', 'factory', 'factory_plate_no', 'spec', 'warning_number', 'warning_order_times', 'warning_days', 'is_warning', 'remark', 'branch_number','print_date','print_direction','pattern_specification','membrane_specification','surface_printing','M_width','pattern_radion','chip_specification_length','finished_specification');
        $params['customer_id'] = $params['customer_id']?$params['customer_id']:0;
        $params['buyer_id'] = $params['buyer_id']?$params['buyer_id']:0;
        $params['warning_days'] = $params['warning_days']?$params['warning_days']:0;
        $params['warning_number'] = $params['warning_number']?$params['warning_number']:0;
        $params['warning_order_times'] = $params['warning_order_times']?$params['warning_order_times']:0;
        $params['print_date'] = $params['print_date']?$params['print_date']:'';//制版日期
        $params['print_direction'] = $params['print_direction']?$params['print_direction']:'';//版的印刷方向
        $params['pattern_specification'] = $params['pattern_specification']?$params['pattern_specification']:'';//图案规格
        $params['membrane_specification'] = $params['membrane_specification']?$params['membrane_specification']:'';//膜规格
        $params['surface_printing'] = $params['surface_printing']?$params['surface_printing']:'';//表里印
        $params['M_width'] = $params['M_width']?$params['M_width']:'';//M边宽度
        $params['pattern_radion'] = $params['pattern_radion']?$params['pattern_radion']:'';//图案占比
        $params['chip_specification_length'] = $params['chip_specification_length']?$params['chip_specification_length']:'';//片料规格
        $params['finished_specification'] = $params['finished_specification']?$params['finished_specification']:'';//成品规格

        //如果未输入版号，生成随机版号 20180601 zhuyujun
        $params['plate_no'] = $params['plate_no']?$params['plate_no']:\App\Engine\Plate::createPlateNo();



        $user_id = Func::getHeaderValueByName('userid');
        $userinfo = DepartmentUser::getCurrentInfo($user_id);

        $rules = [
            'customer_id' => 'integer',
            'buyer_id' => 'required',
            'category_id' => 'required|integer',
            'plate_name' => 'required',
//            'branch_number' => 'required',
            //'img_id' => 'required|integer',
            'warning_days' => 'required|integer',
            'warning_number' => 'required|integer',
            'plate_no' => 'required',
//            'position' => 'required',
//            'factory' => 'required',
//            'factory_plate_no' => 'required',
//            'spec' => 'required',
            'is_warning' => 'required',
            'warning_order_times' => 'integer',
        ];
        $this->validateRequestParameters($params, $rules);

        //图案规格，版规格不允许只填写一个 zhuyujun 20181127
        if($params['spec']){
            $tmpArr = explode(',',$params['spec']);
            if(count($tmpArr) == 2){
                if($tmpArr[0] || $tmpArr[1]){
                    if( !($tmpArr[0] && $tmpArr[1]) ){
                        return [
                            'code' => 1,
                            'message' => '版规格数据请填写完整',
                        ];
                    }
                }
            }
        }
        if($params['pattern_specification']){
            $tmpArr = explode(',',$params['pattern_specification']);
            if(count($tmpArr) == 2){
                if($tmpArr[0] || $tmpArr[1]){
                    if( !($tmpArr[0] && $tmpArr[1]) ){
                        return [
                            'code' => 1,
                            'message' => '图案规格数据请填写完整',
                        ];
                    }
                }
            }
        }






        //限制版号为唯一 20180523 zhuyujun
        if(\App\Eloquent\Ygt\Plate::where(['plate_no'=>$params['plate_no']])->count()){
            return [
                'code' => 1,
                'message' => '版编号已存在，请重新输入'
            ];
        }


        //如果是客商，修改厂ID
        $companyId = $userinfo->company_id;
        if($companyId == 2){
            $tmpObj = \App\Eloquent\Ygt\Customer::where(['id'=>$params['customer_id']])->first();
            if($tmpObj){
                $companyId = $tmpObj->company_id;
            }
        }


        $plateModel = new Plate();

        $createData = [
            'customer_id' => $params['customer_id'],
            'buyer_id' => $params['buyer_id'],
            'category_id' => $params['category_id'],
            'plate_name' => $params['plate_name'],
            'branch_number' => $params['branch_number'] ? $params['branch_number'] : 0,
            'img_id' => $params['img_id'],
            'plate_no' => $params['plate_no'],
            'position' => $params['position'],
            'factory' => $params['factory'],
            'factory_plate_no' => $params['factory_plate_no'],
            'spec' => $params['spec'],
            'warning_number' => $params['warning_number'],
            'warning_order_times' => $params['warning_order_times'],
            'warning_days' => $params['warning_days'],
            'remark' => $params['remark'],
            'is_warning' => $params['is_warning'],
            'last_time' => $_SERVER['REQUEST_TIME'],
            'print_date' => $params['print_date'],
            'print_direction' => $params['print_direction'],
            'pattern_specification' => $params['pattern_specification'],
            'membrane_specification' => $params['membrane_specification'],
            'surface_printing' => $params['surface_printing'],
            'M_width' => $params['M_width'],
            'pattern_radion' => $params['pattern_radion'],
            'chip_specification_length' => $params['chip_specification_length'],
            'finished_specification' => $params['finished_specification'],
            'company_id' => $companyId,
        ];
        $plateId = $plateModel->insertOneData($createData, 'id');

        $branch = request('branch');
//        Log::info($branch);
        $branch = json_decode(htmlspecialchars_decode($branch), true);

        //支版逻辑调整
//        if($branch){
//            foreach ($branch as $key => $val) {
//                $branchData[] = [
//                    'plate_id' => $plateId,
//                    'branch_name' => $val['branch_name'],
//                    'repair_info' => $val['repair_info'],
//                    'remark' => $val['remark'],
//                    'company_id' => $userinfo->company_id,
//                ];
//            }
//            $branchModel = new Branch();
//            $branchModel->insertData($branchData);
//        }

        //新逻辑
        if($branch){
//            if(!isset($branch['fixed_plate']) || !isset($branch['colourplate'])){
//                return [
//                    'code' => 1,
//                    'message' => '版支参数错误'
//                ];
//            }
            if(!isset($branch['fixed_plate'])){
                $branch['fixed_plate'] = [];
            }
            if(!isset($branch['colourplate'])){
                $branch['colourplate'] =[];
            }
            if(!isset($branch['other_plate'])){
                $branch['other_plate'] =[];
            }

            //添加固定版信息
            foreach ($branch['fixed_plate'] as $fixedPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 1,//1-固定板 2-套版
                    'name' => $fixedPlateRow['name'],
                    'is_choose' => $fixedPlateRow['is_choose'],
                    'is_delete' => $fixedPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 1,//1-固定板 2-套版
                    'name' => $fixedPlateRow['name']
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
            }


            //添加套版
            foreach ($branch['colourplate'] as $colourPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 2,//1-固定板 2-套版
                    'name' => $colourPlateRow['name'],
                    'is_choose' => $colourPlateRow['is_choose'],
                    'is_delete' => $colourPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 2,//1-固定板 2-套版
                    'name' => $colourPlateRow['name'],
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpPlateBranchId = $tmpObj->id;

                //添加套版型号
                if(isset($colourPlateRow['model']) && $colourPlateRow['model']){
//                    $tmpModelList = explode(',',$colourPlateRow['model']);
                    $tmpModelList = $colourPlateRow['model'];
                    foreach ($tmpModelList as $tmpModelName){
                        if(trim($tmpModelName)){//过滤空字符串
                            $tmpInsertRow = [
                                'plate_branch_id' => $tmpPlateBranchId,
                                'plate_branch_name' => $colourPlateRow['name'],
                                'name' => $tmpModelName,
                            ];


                            $tmpWhere = [
                                'plate_branch_id' => $tmpPlateBranchId,
                                'plate_branch_name' => $colourPlateRow['name'],
                                'name' => $tmpModelName,
                            ];
                            $tmpObj = \App\Eloquent\Ygt\PlateBranchColourplate::firstOrNew(['plate_branch_id' => $tmpPlateBranchId,'name' =>$tmpModelName]);
                            $tmpObj->fill($tmpInsertRow);
                            $tmpObj->save();
                        }
                    }
                }
            }

            //其他版
            //添加固定版信息
            $tmpFixedPlateNameArr = [];
            foreach ($branch['other_plate'] as $otherPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 3,//1-固定板 2-套版 3-其他版
                    'name' => $otherPlateRow['name'],
                    'is_choose' => 1,
                    'is_delete' => 1,
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 3,//1-固定板 2-套版
                    'name' => $otherPlateRow['name']
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpFixedPlateNameArr[] = $otherPlateRow['name'];
            }
        }


        $returnData = [
            'msg' => 'ok',
            'plate_id' => $plateId
        ];
        return $returnData;
    }

    /**
     * @return array
     * 编辑版
     */
    public function plateEdit()
    {
        $params = request()->only('id', 'customer_id', 'buyer_id', 'category_id', 'plate_name', 'img_id', 'plate_no', 'position', 'factory', 'factory_plate_no', 'spec', 'warning_number', 'warning_order_times', 'is_warning', 'warning_days', 'remark', 'branch_number','print_date','print_direction','pattern_specification','membrane_specification','surface_printing','M_width','pattern_radion','chip_specification_length','finished_specification');
        $params['customer_id'] = $params['customer_id']?$params['customer_id']:0;
        $params['buyer_id'] = $params['buyer_id']?$params['buyer_id']:0;
        $params['warning_days'] = $params['warning_days']?$params['warning_days']:0;
        $params['warning_number'] = $params['warning_number']?$params['warning_number']:0;
        $params['warning_order_times'] = $params['warning_order_times']?$params['warning_order_times']:0;
        $params['print_date'] = $params['print_date']?$params['print_date']:'';//制版日期
        $params['print_direction'] = $params['print_direction']?$params['print_direction']:'';//版的印刷方向
        $params['pattern_specification'] = $params['pattern_specification']?$params['pattern_specification']:'';//图案规格
        $params['membrane_specification'] = $params['membrane_specification']?$params['membrane_specification']:'';//膜规格
        $params['surface_printing'] = $params['surface_printing']?$params['surface_printing']:'';//表里印
        $params['M_width'] = $params['M_width']?$params['M_width']:'';//M边宽度
        $params['pattern_radion'] = $params['pattern_radion']?$params['pattern_radion']:'';//图案占比
        $params['chip_specification_length'] = $params['chip_specification_length']?$params['chip_specification_length']:'';//片料规格
        $params['finished_specification'] = $params['finished_specification']?$params['finished_specification']:'';//成品规格

        $user_id = Func::getHeaderValueByName('userid');
        $userinfo = DepartmentUser::getCurrentInfo($user_id);

        $rules = [
            'id' => 'required|integer',
            'customer_id' => 'integer',
            'buyer_id' => 'integer',
            'category_id' => 'required|integer',
            'plate_name' => 'required',
//            'branch_number' => 'required',
            'warning_days' => 'required|integer',
            'warning_number' => 'required|integer',
            //'img_id' => 'required|integer',
//            'plate_no' => 'required',
//            'position' => 'required',
//            'factory' => 'required',
//            'factory_plate_no' => 'required',
//            'spec' => 'required',
            'is_warning' => 'required',
            'warning_order_times' => 'integer',
        ];
        $this->validateRequestParameters($params, $rules);



        //图案规格，版规格不允许只填写一个 zhuyujun 20181127
        if($params['spec']){
            $tmpArr = explode(',',$params['spec']);
            if(count($tmpArr) == 2){
                if($tmpArr[0] || $tmpArr[1]){
                    if( !($tmpArr[0] && $tmpArr[1]) ){
                        return [
                            'code' => 1,
                            'message' => '版规格数据请填写完整',
                        ];
                    }
                }
            }
        }
        if($params['pattern_specification']){
            $tmpArr = explode(',',$params['pattern_specification']);
            if(count($tmpArr) == 2){
                if($tmpArr[0] || $tmpArr[1]){
                    if( !($tmpArr[0] && $tmpArr[1]) ){
                        return [
                            'code' => 1,
                            'message' => '图案规格数据请填写完整',
                        ];
                    }
                }
            }
        }

        //限制版号为唯一 20180523 zhuyujun
        $tmpPlateObj = \App\Eloquent\Ygt\Plate::where(['plate_no'=>$params['plate_no']])->first();
        if($tmpPlateObj && $tmpPlateObj->id != $params['id']){
            return [
                'code' => 1,
                'message' => '版编号已存在，请重新输入'
            ];
        }

        //如果是客商，修改厂ID
        $companyId = $userinfo->company_id;
        if($companyId == 2){
            $tmpObj = \App\Eloquent\Ygt\Customer::where(['id'=>$params['customer_id']])->first();
            if($tmpObj){
                $companyId = $tmpObj->company_id;
            }
        }


        $plateModel = new Plate();

        $createData = [
            'customer_id' => $params['customer_id'],
            'buyer_id' => $params['buyer_id'],
            'category_id' => $params['category_id'],
            'plate_name' => $params['plate_name'],
            'branch_number' => $params['branch_number'],
            'img_id' => $params['img_id'],
            'plate_no' => $params['plate_no'],
            'position' => $params['position'],
            'factory' => $params['factory'],
            'factory_plate_no' => $params['factory_plate_no'],
            'spec' => $params['spec'],
            'warning_number' => $params['warning_number'],
            'warning_order_times' => $params['warning_order_times'],
            'warning_days' => $params['warning_days'],
            'remark' => $params['remark'],
            'is_warning' => $params['is_warning'],
            'print_date' => $params['print_date'],
            'print_direction' => $params['print_direction'],
            'pattern_specification' => $params['pattern_specification'],
            'membrane_specification' => $params['membrane_specification'],
            'surface_printing' => $params['surface_printing'],
            'M_width' => $params['M_width'],
            'pattern_radion' => $params['pattern_radion'],
            'chip_specification_length' => $params['chip_specification_length'],
            'finished_specification' => $params['finished_specification'],
            'company_id' => $companyId,
        ];
        $where = ['id' => $params['id']];

        if (!$plateId = $plateModel->updateOneData($where, $createData, 'id')) {
            xThrow(ERR_PLATE_IS_NOT_EXIST);
        }

        $branch = request('branch');
        $branch = json_decode(htmlspecialchars_decode($branch), true);

//        $branchModel = new Branch();
//        if($branch){
//            foreach ($branch as $key => $val) {
//                if (isset($val['id'])) {
//                    $branchUpdateData = [
//                        'plate_id' => $plateId,
//                        'branch_name' => $val['branch_name'],
//                        'repair_info' => $val['repair_info'],
//                        'remark' => $val['remark'],
//                        'company_id' => $userinfo->company_id,
//                    ];
//                    $branchModel->updateOneData(['id' => $val['id']], $branchUpdateData);
//                } else {
//                    $branchCreateData[] = [
//                        'plate_id' => $plateId,
//                        'branch_name' => $val['branch_name'],
//                        'repair_info' => $val['repair_info'],
//                        'remark' => $val['remark'],
//                        'company_id' => $userinfo->company_id,
//                    ];
//                }
//            }
//        }
//        if (isset($branchCreateData)) {
//            $branchModel->insertData($branchCreateData);
//        }
        //新逻辑
        if($branch){
//            if(!isset($branch['fixed_plate']) || !isset($branch['colourplate'])){
//                return [
//                    'code' => 1,
//                    'message' => '版支参数错误'
//                ];
//            }
            if(!isset($branch['fixed_plate'])){
                $branch['fixed_plate'] = [];
            }
            if(!isset($branch['colourplate'])){
                $branch['colourplate'] =[];
            }
            if(!isset($branch['other_plate'])){
                $branch['other_plate'] =[];
            }

            //添加固定版信息
            $tmpFixedPlateNameArr = [];
            foreach ($branch['fixed_plate'] as $fixedPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 1,//1-固定板 2-套版
                    'name' => $fixedPlateRow['name'],
                    'is_choose' => $fixedPlateRow['is_choose'],
                    'is_delete' => $fixedPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 1,//1-固定板 2-套版
                    'name' => $fixedPlateRow['name']
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpFixedPlateNameArr[] = $fixedPlateRow['name'];
            }

            //已删除的处理-固定板
            \App\Eloquent\Ygt\PlateBranch::where(['plate_id' => $plateId,'type'=>1])->WhereNotIn('name',$tmpFixedPlateNameArr)->delete();


            //添加套版
            $tmpColourPlateNameArr = [];
            foreach ($branch['colourplate'] as $colourPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 2,//1-固定板 2-套版
                    'name' => $colourPlateRow['name'],
                    'is_choose' => $colourPlateRow['is_choose'],
                    'is_delete' => $colourPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 2,//1-固定板 2-套版
                    'name' => $colourPlateRow['name'],
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpPlateBranchId = $tmpObj->id;
                $tmpColourPlateNameArr[] = $colourPlateRow['name'];

                //添加套版型号
                $tmpModelNameArr = [];
                if(isset($colourPlateRow['model']) && $colourPlateRow['model']){
//                    $tmpModelList = explode(',',$colourPlateRow['model']);
                    $tmpModelList = $colourPlateRow['model'];
                    foreach ($tmpModelList as $tmpModelName){
                        if(trim($tmpModelName)){//过滤空字符串
                            $tmpInsertRow = [
                                'plate_branch_id' => $tmpPlateBranchId,
                                'plate_branch_name' => $colourPlateRow['name'],
                                'name' => $tmpModelName,
                            ];

                            $tmpModelNameArr[] = $tmpModelName;

                            $tmpWhere = [
                                'plate_branch_id' => $tmpPlateBranchId,
                                'plate_branch_name' => $colourPlateRow['name'],
                                'name' => $tmpModelName,
                            ];
                            $tmpObj = \App\Eloquent\Ygt\PlateBranchColourplate::firstOrNew(['plate_branch_id' => $tmpPlateBranchId,'name' =>$tmpModelName]);
                            $tmpObj->fill($tmpInsertRow);
                            $tmpObj->save();
                        }
                    }
                }

                //已删除的处理-套版-套版子类型
                \App\Eloquent\Ygt\PlateBranchColourplate::where(['plate_branch_id' => $tmpPlateBranchId])->WhereNotIn('name',$tmpModelNameArr)->delete();
            }
            //已删除的处理-套版
            \App\Eloquent\Ygt\PlateBranch::where(['plate_id' => $plateId,'type'=>2])->WhereNotIn('name',$tmpColourPlateNameArr)->delete();

            //其他版
            //添加固定版信息
            $tmpFixedPlateNameArr = [];
            foreach ($branch['other_plate'] as $otherPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 3,//1-固定板 2-套版 3-其他版
                    'name' => $otherPlateRow['name'],
//                    'is_choose' => $otherPlateRow['is_choose'],
//                    'is_delete' => $otherPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 3,//1-固定板 2-套版
                    'name' => $otherPlateRow['name']
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpFixedPlateNameArr[] = $otherPlateRow['name'];
            }

            //已删除的处理-其他版
            \App\Eloquent\Ygt\PlateBranch::where(['plate_id' => $plateId,'type'=>3])->WhereNotIn('name',$tmpFixedPlateNameArr)->delete();
        }


        $returnData = [
            'msg' => 'ok',
            'plate_id' => $plateId
        ];
        return $returnData;
    }

    /**
     * @return string
     * 删除版
     */
    public function plateDel()
    {
        $userId = Func::getHeaderValueByName('userid');
        $userInfo = DepartmentUser::getCurrentInfo($userId);
        $companyId = isset($userInfo['company_id']) ? $userInfo['company_id'] : '';

        $plateId = request('id');

        if($companyId == 2){
            $where = [
                'id'=>$plateId,
//                'company_id'=>$companyId,
            ];
        }else{
            $where = [
                'id'=>$plateId,
//                'company_id'=>$companyId,
            ];
        }

        $plateModel = new Plate();
        if($plateModel->del($where)){
            $branchModel = new Branch();
            $branchModel->del(['plate_id'=>$plateId]);
            return 'ok';
        }else{
            xThrow(ERR_PLATE_DELETE_FAIL);
        }

    }

    public function PlateSearchHistory(){
        $userId = Func::getHeaderValueByName('userid');
        $plateSearchModel = new PlateSearch();
        $serachInfo = $plateSearchModel->getOneData(['uid'=>$userId],'',['uid','desc']);
        return unserialize($serachInfo['content']);
    }


    //版的印刷方向
    public function getPrintDirectionList(){
        $printDirectionList = [
            [
                'id' => 1,
                'title' => '从头印',
            ],
            [
                'id' => 2,
                'title' => '从尾印',
            ],
        ];

        return $printDirectionList;
    }

    //取板大图
    public function getImg()
    {
        $id             = request('id',0);
        if(!$id)
        {
            xThrow( ERR_PARAMETER );
        }
        $where          = ['id'=>$id];
        $info           = Plate::getInfo($where);
        $imgList        = '';
        if($info)
        {
            $plate      = $info->toArray();
            $imgId      = $plate['img_id'];
            $imgUrl     = Func::getImgUrlById($imgId,false);
            if(empty($imgUrl)){
                $imgList = [];
            }
            else{
                $imgList  = [$imgUrl];
            }
        }
        $result         = [ 'img_list'=>$imgList ];
        return $result;
    }

    //搜索类似版的版位
    public function searchPrintPosition(){
        $customerId = request('customer_id');
        $buyerId = request('buyer_id');
        $plateName = request('plate_name');
        $categoryId = request('category_id');


        //客户名，单位名称，品名依次搜索
        $position = "";
        $plateId = 0;
        if($customerId){
            $tmpWhere = [];
            $tmpWhere[] = ['customer_id','=',$customerId];
            $tmpWhere[] = ['position','!=',''];
            $tmpWhere[] = ['category_id','=',$categoryId];
            $tmpPlateRow = \App\Eloquent\Ygt\Plate::where($tmpWhere)->orderBy('id','desc')->first();
            if($tmpPlateRow){
                $position = $tmpPlateRow['position'];
                $plateId = $tmpPlateRow['id'];

                $tmpWhere = [];
                $tmpWhere[] = ['customer_id','=',$customerId];
                $tmpWhere[] = ['buyer_id','=',$buyerId];
                $tmpWhere[] = ['position','!=',''];
                $tmpWhere[] = ['category_id','=',$categoryId];
                $tmpPlateRow = \App\Eloquent\Ygt\Plate::where($tmpWhere)->orderBy('id','desc')->first();
                if($tmpPlateRow){
                    $position = $tmpPlateRow['position'];
                    $plateId = $tmpPlateRow['id'];

                    $tmpWhere = [];
                    $tmpWhere[] = ['customer_id','=',$customerId];
                    $tmpWhere[] = ['buyer_id','=',$buyerId];
                    $tmpWhere[] = ['plate_name','=',$plateName];
                    $tmpWhere[] = ['position','!=',''];
                    $tmpWhere[] = ['category_id','=',$categoryId];
                    $tmpPlateRow = \App\Eloquent\Ygt\Plate::where($tmpWhere)->orderBy('id','desc')->first();
                    if($tmpPlateRow){
                        $position = $tmpPlateRow['position'];
                        $plateId = $tmpPlateRow['id'];
                    }
                }
            }
        }


        if($plateId){
            $re = [[
                'position' => $position ? $position : '',//过滤null
                'plate_id' => $plateId,
            ]];
        }else{
            $re = [];
        }

        return $re;
    }


    //版支，套版处理
    public function editPlateBranch(){

        $plateId = request('plate_id');

        if(!$plateId){
            return [
                'code' => 1,
                'message' => '参数错误',
            ];
        }

        $branch = request('branch');
        $branch = json_decode(htmlspecialchars_decode($branch), true);

        if($branch){
//            if(!isset($branch['fixed_plate']) || !isset($branch['colourplate'])){
//                return [
//                    'code' => 1,
//                    'message' => '版支参数错误'
//                ];
//            }
            if(!isset($branch['fixed_plate'])){
                $branch['fixed_plate'] = [];
            }
            if(!isset($branch['colourplate'])){
                $branch['colourplate'] =[];
            }
            if(!isset($branch['other_plate'])){
                $branch['other_plate'] =[];
            }

            //添加固定版信息
            $tmpFixedPlateNameArr = [];
            foreach ($branch['fixed_plate'] as $fixedPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 1,//1-固定板 2-套版
                    'name' => $fixedPlateRow['name'],
                    'is_choose' => $fixedPlateRow['is_choose'],
                    'is_delete' => $fixedPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 1,//1-固定板 2-套版
                    'name' => $fixedPlateRow['name']
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpFixedPlateNameArr[] = $fixedPlateRow['name'];
            }

            //已删除的处理-固定板
            \App\Eloquent\Ygt\PlateBranch::where(['plate_id' => $plateId,'type'=>1])->WhereNotIn('name',$tmpFixedPlateNameArr)->delete();


            //添加套版
            $tmpColourPlateNameArr = [];
            foreach ($branch['colourplate'] as $colourPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 2,//1-固定板 2-套版
                    'name' => $colourPlateRow['name'],
                    'is_choose' => $colourPlateRow['is_choose'],
                    'is_delete' => $colourPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 2,//1-固定板 2-套版
                    'name' => $colourPlateRow['name'],
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpPlateBranchId = $tmpObj->id;
                $tmpColourPlateNameArr[] = $colourPlateRow['name'];

                //添加套版型号
                $tmpModelNameArr = [];
                if(isset($colourPlateRow['model']) && $colourPlateRow['model']){
//                    $tmpModelList = explode(',',$colourPlateRow['model']);
                    $tmpModelList = $colourPlateRow['model'];
                    foreach ($tmpModelList as $tmpModelName){
                        if(trim($tmpModelName)){//过滤空字符串
                            $tmpInsertRow = [
                                'plate_branch_id' => $tmpPlateBranchId,
                                'plate_branch_name' => $colourPlateRow['name'],
                                'name' => $tmpModelName,
                            ];

                            $tmpModelNameArr[] = $tmpModelName;

                            $tmpWhere = [
                                'plate_branch_id' => $tmpPlateBranchId,
                                'plate_branch_name' => $colourPlateRow['name'],
                                'name' => $tmpModelName,
                            ];
                            $tmpObj = \App\Eloquent\Ygt\PlateBranchColourplate::firstOrNew(['plate_branch_id' => $tmpPlateBranchId,'name' =>$tmpModelName]);
                            $tmpObj->fill($tmpInsertRow);
                            $tmpObj->save();
                        }
                    }
                }

                //已删除的处理-套版-套版子类型
                \App\Eloquent\Ygt\PlateBranchColourplate::where(['plate_branch_id' => $tmpPlateBranchId])->WhereNotIn('name',$tmpModelNameArr)->delete();
            }
            //已删除的处理-套版
            \App\Eloquent\Ygt\PlateBranch::where(['plate_id' => $plateId,'type'=>2])->WhereNotIn('name',$tmpColourPlateNameArr)->delete();

            //其他版
            //添加固定版信息
            $tmpFixedPlateNameArr = [];
            foreach ($branch['other_plate'] as $otherPlateRow){
                $tmpInsertRow = [
                    'plate_id' => $plateId,
                    'type' => 3,//1-固定板 2-套版 3-其他版
                    'name' => $otherPlateRow['name'],
//                    'is_choose' => $otherPlateRow['is_choose'],
//                    'is_delete' => $otherPlateRow['is_delete'],
                ];
                $tmpWhere = [
                    'plate_id' => $plateId,
                    'type' => 3,//1-固定板 2-套版
                    'name' => $otherPlateRow['name']
                ];
                $tmpObj = \App\Eloquent\Ygt\PlateBranch::firstOrNew($tmpWhere);
                $tmpObj->fill($tmpInsertRow);
                $tmpObj->save();
                $tmpFixedPlateNameArr[] = $otherPlateRow['name'];
            }

            //已删除的处理-其他版
            \App\Eloquent\Ygt\PlateBranch::where(['plate_id' => $plateId,'type'=>3])->WhereNotIn('name',$tmpFixedPlateNameArr)->delete();
        }




        return '操作成功';
    }

    //创建订单（工单）选择版的详情
    public function getPlateBranchDetail(){
//        request('id') --版ID

        //追加版支详情
        $info = [];
        $branch = [
            'fixed_plate' => [],
            'colourplate' => [],
        ];
        $plateBranchList = \App\Eloquent\Ygt\PlateBranch::where(['plate_id'=>request('id')])->get();
        foreach ($plateBranchList as $plateBranchRow){
            if($plateBranchRow['type'] == 1){

                if($plateBranchRow['is_choose']){
                    $branch['fixed_plate'][] = [
                        'id' => $plateBranchRow['id'],
                        'name' => $plateBranchRow['name'],
                        'is_choose' => $plateBranchRow['is_choose'],//1-选中，0-未选中]
                        'is_delete' => $plateBranchRow['is_delete'],//是否可删除 1-可删除 0-不可删除
                    ];
                }
            }

            if($plateBranchRow['type'] == 2){
                $tmpPlateBranchId = $plateBranchRow['id'];

                $tmpModelList=[];
                $tmpPlateBranchColourplateList = \App\Eloquent\Ygt\PlateBranchColourplate::where(['plate_branch_id'=>$tmpPlateBranchId])->get();
                foreach ($tmpPlateBranchColourplateList as $tmpPlateBranchColourRow){
                    $tmpModelList[] = ['name' => $tmpPlateBranchColourRow['name']];
                }

                if(!empty($tmpModelList)){
                    if($plateBranchRow['is_choose']){
                        $branch['colourplate'][] = [
                            'id' => $plateBranchRow['id'],
                            'name' => $plateBranchRow['name'],
                            'is_choose' => $plateBranchRow['is_choose'],//1-选中，0-未选中
                            'is_delete' => $plateBranchRow['is_delete'],//是否可删除 1-可删除 0-不可删除
                            'model' => $tmpModelList,
                        ];
                    }
                }
            }

            if($plateBranchRow['type'] == 3){
                $branch['other_plate'][] = [
                    'id' => $plateBranchRow['id'],
                    'name' => $plateBranchRow['name'],
                    'is_delete' => $plateBranchRow['is_delete'],//是否可删除 1-可删除 0-不可删除
                ];
            }
        }

        $info['branch'] = $branch;

        //增加版类型ID
        $tmpPlateRow = \App\Eloquent\Ygt\Plate::where(['id'=>request('id')])->first();
        $categoryId = '';
        if($tmpPlateRow){
            $categoryId = $tmpPlateRow['category_id'];
        }

        $info['category_id'] = $categoryId;



        return $info;

    }


}